package com.example.studyapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.PowerManager;
import android.text.TextUtils;
import android.util.Log;

import com.example.activity.BarChartActivity;
import com.example.activity.CanvasActivity;
import com.example.activity.CardViewActivity;
import com.example.activity.CoordinatorLayoutActivity;
import com.example.activity.DialogActivity;
import com.example.activity.NestScrollActivity;
import com.example.activity.PkActivity;
import com.example.activity.RecyclerViewActivity;
import com.example.activity.RxjavaActivity;
import com.example.activity.ServiceActivity;
import com.example.activity.TouchEventActivity;
import com.example.activity.ViewPagerFragmentActivity;
import com.example.adapter.MainRvAdapter;
import com.example.interfacePackage.RvClickInterface;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private RecyclerView mRvFunction;
    private List<String> mRvList;
    private MainRvAdapter mMainRvAdapter;
    private PowerKeyBroadcastReceiver mPowerKeyBroadcastReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initData();
    }

    private void initView() {
        mRvFunction = findViewById(R.id.rv_function);
    }

    private void initData() {

        mRvList = new ArrayList<>();
        mRvList.add("Canvas");
        mRvList.add("Service");
        mRvList.add("RecyclerView");
        mRvList.add("BarChart");
        mRvList.add("ViewPagerFragment懒加载");
        mRvList.add("Rxjava");
        mRvList.add("PKCustom");
        mRvList.add("Coordinatorlayout");
        mRvList.add("CardView");
        mRvList.add("Dialog");
        mRvList.add("TouchEvent");
        mRvList.add("NestScroll");
        mRvList.add("offsetX");

        mRvFunction.setLayoutManager(new LinearLayoutManager(this));
        mMainRvAdapter = new MainRvAdapter(this, mRvList);
        mRvFunction.setAdapter(mMainRvAdapter);
        mMainRvAdapter.setOnItemClickListener(new RvClickInterface() {
            @Override
            public void OnItemClickListener(int position) {
                switch (position) {
                    case 0:
                        CanvasActivity.startActivity(MainActivity.this);
                        break;
                    case 1:
                        ServiceActivity.startActivity(MainActivity.this);
                        break;
                    case 2:
                        RecyclerViewActivity.startActivity(MainActivity.this);
                        break;
                    case 3:
                        BarChartActivity.startActivity(MainActivity.this);
                        break;
                    case 4:
                        ViewPagerFragmentActivity.startActivity(MainActivity.this);
                        break;
                    case 5:
                        RxjavaActivity.startActivity(MainActivity.this);
                        break;
                    case 6:
                        PkActivity.startActivity(MainActivity.this);
                        break;
                    case 7:
                        CoordinatorLayoutActivity.startActivity(MainActivity.this);
                        break;
                    case 8:
                        CardViewActivity.startActivity(MainActivity.this);
                        break;
                    case 9:
                        DialogActivity.startActivity(MainActivity.this);
                        break;
                    case 10:
                        TouchEventActivity.startActivity(MainActivity.this);
                        break;
                    case 11:
                        NestScrollActivity.startActivity(MainActivity.this);
                        break;
                        case 12:
                        NestScrollActivity.startActivity(MainActivity.this);
                        break;
                    default:
                        break;
                }
            }
        });

    }

    /**
     * 注册power键按下监听广播
     */
    private void registerPowerBroadCast() {
        IntentFilter mIntentFilter = new IntentFilter();
        mIntentFilter.addAction(Intent.ACTION_SCREEN_ON);
        mIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
        mPowerKeyBroadcastReceiver = new PowerKeyBroadcastReceiver();
        registerReceiver(mPowerKeyBroadcastReceiver, mIntentFilter);
    }

    /**
     * power键监听
     */
    //广播接收者
    static class PowerKeyBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(Intent.ACTION_SCREEN_OFF)) {
            }
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

            Log.d("ghj", "11111");
            if (pm.isScreenOn()) {


            } else {


            }

        }
    }

}